package com.sunmnet.auto.spring.mvc.variable.impl;

import com.sunmnet.auto.spring.mvc.baen.FieldSturcture;
import com.sunmnet.auto.spring.mvc.baen.TBStructure;
import com.sunmnet.auto.spring.mvc.temp.FileType;
import com.sunmnet.auto.spring.mvc.variable.IVarDeal;

/**
 * <PRE>
 * {类说明}
 * </PRE>
 * <B>项    目：</B>
 * <B>技术支持：</B> 广东三盟科技股份有限公司 (c) 2015
 * @version   1.0 2015年6月15日
 * @author    黄坚：huangjian@sunmnet.com
 * @since     jdk版本：jdk1.6
 */
public class GetSetDeal implements IVarDeal {

	public String excute(FileType type, TBStructure tb) {
        StringBuilder sb = new StringBuilder();
        
        for(FieldSturcture field  : tb.getFields()){
        	if("id".equalsIgnoreCase(field.getName()) ||
        		"create_time".equalsIgnoreCase(field.getName()) ||
        		"modify_time".equalsIgnoreCase(field.getName())){
        		continue;
        	}
        	if("date".equalsIgnoreCase(field.getType())){
        		sb.append("    /** ").append(field.getName()).append(" */\r\n");
                sb.append("    private ").append(field.getType()).append(" ");
                sb.append(field.getPropertyName()).append(" = new ").append(field.getType()).append("();\r\n\r\n");
        	}else {
	        	sb.append("    /** ").append(field.getName()).append(" */\r\n");
	            sb.append("    private ").append(field.getType()).append(" ");
	            sb.append(field.getPropertyName()).append(";\r\n\r\n");
        	}
        }
        for(FieldSturcture field  : tb.getFields()) {
            //getter
            sb.append("    /**\r\n");
            sb.append("     * get").append(field.getMethodName()).append("\r\n");
            sb.append("     * @return ").append(field.getType()).append("\r\n");
            sb.append("     */\r\n");
            sb.append("    @Column(").append("name = ").append("\"").append(field.getName()).append("\"").append(")");
            sb.append("\r\n");
            sb.append("    public ").append(field.getType());
            sb.append(" get").append(field.getMethodName()).append("() {\r\n");
            sb.append("        return this.").append(field.getPropertyName());
            sb.append(";\r\n    }\r\n\r\n");

            //setter
            sb.append("    /**\r\n");
            sb.append("     * set").append(field.getMethodName()).append("\r\n");
            sb.append("     * @param ").append(field.getPropertyName());
            sb.append(" ").append(field.getPropertyName()).append(" to set\r\n");
            sb.append("     */\r\n");
            sb.append("    public void");
            sb.append(" set").append(field.getMethodName());
            sb.append("(").append(field.getType()).append(" ");
            sb.append(field.getPropertyName()).append(") {\r\n");
            sb.append("        this.").append(field.getPropertyName()).append(" = ");
            sb.append(field.getPropertyName()).append(";\r\n    }\r\n\r\n");
        }
		return sb.toString();
	}

}
